package com.project.Service.impl;


import com.project.Bean.Student;
import com.project.Bean.User;
import com.project.Service.IStudentService;
import com.project.mapper.IStudentMapper;
import com.project.mapper.IUserMapper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/***
 * 学生实现类
 */
public class IStudentServiceImpl extends BaseService  implements IStudentService {

    @Override
    public List<Student> findAll(String name, String classRoom, String room) {
        SqlSession session = this.getSession();
       IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        List<Student> list = mapper.findAll(name,classRoom,room);
        session.close();
        return list;

    }

    @Override
    public void addStudent(Student s) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
         mapper.addStudent(s);
         session.commit();
        session.close();
    }

    @Override
    public void delStudent(int id) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.delStudent(id);
        session.commit();
        session.close();
    }

    @Override
    public void changeRoom(int id, int roomId) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.changeRoom(id,roomId);
        session.commit();
        session.close();
    }

    @Override
    public Student findById(int id) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        Student student = mapper.findById(id);
        session.close();
        return student;
    }
}
